<template>
  <div>
    <Loading v-show="state === 'logging'"></Loading>
    <Avatar
      v-show="state === 'logged'"
      :name="user.name"
      :avatar="user.avatar"
      @emitAvatarEvent="handleAvatarEvent"
    />
    <div class="btn">
      <Button v-show="state === 'unlogged'" class="submit" @click="login">
        登入
      </Button>
    </div>
  </div>
</template>

<script lang="ts">
import Avatar from '@/components/Avatar.vue';
import Loading from '@/components/Loading.vue';
import { defineComponent } from '@vue/composition-api';
import { useUser } from '@/hooks';
import { Button } from 'vant';
import '@/service/user';

export default defineComponent({
  components: {
    Avatar,
    Button,
    Loading,
  },
  setup() {
    const handleAvatarEvent = (params: unknown) => {
      console.log('handleAvatarEvent:', params);
    };

    return {
      ...useUser(),
      handleAvatarEvent,
    };
  },
});
</script>

<style lang="postcss" scoped>
.avatar {
  margin: 0 auto;
  display: flex;
  width: 100px;
  height: 100px;
  border-radius: 100px;
  .pic {
    object-fit: cover;
  }
}

.btn {
  position: fixed;
  left: 50%;
  top: 100px;
  transform: translateX(-50%);
}
</style>

// 全局
<style lang="postcss">
.avatar {
}
</style>
